var prefix = jsctx + "/memberRefundApply";

var memberRefundApply = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 120;

    function load() {

        var transferType = $("#transferType").val();
        var isVerification = $("#isVerification").val();

        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageMemberRefundApply",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    cache: false,
                    pageSize: 10,
                    pageList: [10, 20, 30],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    rightFixedColumns: true,
                    height: h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,

                            nickname: $("#nickname").val().trim(),
                            mobile: $("#mobile").val().trim(),
                            status: $("#status").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            endTime: $("#endTime").val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'center',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },

                        {field: 'outTradeNo', title: '申请单号', width: '80', align: 'center'},
                        {field: 'memberId', title: '客户ID', width: '80', align: 'center'},
                        {field: 'nickname', title: '客户名称', width: '80', align: 'center'},
                        {field: 'refundMemberType', title: '客户类型', width: '110', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '渠道商'
                                } else if (value == '1') {
                                    return '加盟商'
                                } else if (value == '2') {
                                    return '-'
                                }
                            }
                         },
                        {field: 'mobile', title: '手机号', width: '110', align: 'center'},
                        {field: 'refundAmount', title: '申请金额', width: '110', align: 'center'},
                        {field: 'createdTime', title: '申请日期', width: '110', align: 'center',
                            formatter: function (value, row, index) {
                                var d = new Date(value);
                                var d2 = d.getFullYear() + "/"+ (d.getMonth() + 1) +"/"+ d.getDate();
                                return "<span>"+d2+"</span>";
                            }
                            },
                        {field: 'faceAmount', title: '打款金额', width: '110', align: 'center'},
                        {
                            field: 'refundBy', title: '微信/支付宝账户',
                            width: '200', align: 'center',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '微信'
                                } else if (value == '1') {
                                    return '支付宝'
                                } else if (value == '2') {
                                    return '银行卡'
                                }
                            }
                        },
                        {field: '', title: '银行名称', width: '110', align: 'center'},
                        {field: '', title: '银行卡号', width: '110', align: 'center'},
                        {field: '', title: '持卡人', width: '110', align: 'center'},
                        {
                            field: 'status', title: '状态',
                            width: '100', align: 'center',
                            class: 'operateBefore-td',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '未审核'
                                } /*else if (value == '1') {
                                    return '处理'
                                }*/ else if (value == '2') {
                                    return '已驳回'
                                } else if (value == '3') {
                                    return '转账中'
                                } else if (value == '4') {
                                    return '已到账'
                                } else if (value == '5') {
                                    return '审批不通过'
                                }
                            }
                        },
                        {
                            title: '操作',
                            field: 'roleId',
                            width: '200', align: 'center',
                            class: 'operate-td',
                            formatter: function (value, row, index) {
                                var action = '';
                                //var b = '';
                                if (row.status=='0'){

                                    action += '<a class="btn btn-success btn-sm " href="#" title="审核" ' +
                                        'onclick="memberRefundApply.showModel(\''
                                        + row.refundApplyId
                                        + '\')">审核</a> ';
                                }
                                action += '<a class="btn btn-success btn-sm " href="#" title="删除"' +
                                    ' onclick="memberRefundApply.deleteMemberRefundApply(\''
                                    + row.refundApplyId
                                    + '\')">删除</a> ';
                                return action;

                            }
                        }
                    ]
                });
    }
    function reLoad() {
        $(".fixed-table-header-columns").css("display", "none");
        $(".fixed-table-body-columns").css("display", "none");
        $('#exampleTable').bootstrapTable('refresh');
    }
    var isajaxsendForPass = true;

    function deleteMemberRefundApply(memberRefundApplyId) {
        layer.confirm('确定要删除选中的提现订单？', {
            btn: ['确定', '取消']
        }, function (index) {
            $.ajax({
                url: prefix + "/deleteMemberRefundApply",
                type: "post",
                data: {
                    'memberRefundApplyId': memberRefundApplyId
                },
                success: function (data) {
                    layer.close(index);
                    if (data.status == 200) {
                        layer.msg("删除成功");
                        reLoad();
                    } else {
                        layer.msg(data.message);
                    }
                }
            });
        })
    }

    function showModel(memberRefundApplyId) {
        $('#exampleModal').modal('show')

        $("#submitForm").unbind("click").bind("click", function () {
            $.ajax({
                url: prefix + "/updateStatus",
                type: "post",
                data: {
                    "memberRefundApplyId": memberRefundApplyId,
                    "status": $("#auditStatus").val(),
                    "remark": $("#remark").val()
                },
                dataType: "json",
                /* processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                 contentType: false, // 告诉jQuery不要去设置Content-Type请求头*/
                success: function (data) {
                    if (data.status == 200) {
                        parent.layer.msg(data.message);
                        $('#exampleModal').on('hidden.bs.modal', function () {
                            document.getElementById("contentForm").reset();
                        })
                        $('#exampleModal').modal('hide')
                        reLoad();
                    } else {
                        parent.layer.alert(data.message);
                        $('#exampleModal').on('hidden.bs.modal', function () {
                            document.getElementById("contentForm").reset();
                        })
                    }

                }
            })
        })
    }

    /*function showModel(memberRefundApplyId) {
        debugger
        $('#exampleModal').modal('show')

        $("#submitForm").unbind("click").bind("click", function () {
            $.ajax({
                url: prefix + "/updateStatus",
                type: "post",
                data: {
                    "memberRefundApplyId": memberRefundApplyId,
                    "status": $("#auditStatus").val(),
                    "remark": $("#remark").val()
                },
                dataType: "json",
                /!* processData: false, // 告诉jQuery不要去处理发送的数据，用于对data参数进行序列化处理 这里必须false
                 contentType: false, // 告诉jQuery不要去设置Content-Type请求头*!/
                success: function (data) {
                    if (data.status == 200) {
                        parent.layer.msg("操作成功");
                        $('#exampleModal').on('hidden.bs.modal', function () {
                            document.getElementById("contentForm").reset();
                        })
                        $('#exampleModal').modal('hide')
                        reLoad();
                    } else {
                        parent.layer.alert(data.message);
                        $('#exampleModal').on('hidden.bs.modal', function () {
                            document.getElementById("contentForm").reset();
                        })
                    }

                }
            })
        })
    }*/

    function goBack() {
        window.history.back();
    }

    function exportMemberRefundApply() {
        $.fileDownload(prefix + "/exportMemberRefundApply", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                nickname: $("#nickname").val().trim(),
                mobile: $("#mobile").val().trim(),
                status: $("#status").val().trim(),
                startTime: $("#startTime").val().trim(),
                endTime: $("#endTime").val().trim(),

                /*refundSource: $("#refundSource").val().trim(),
                outTradeNo: $("#outTradeNo").val().trim(),
                refundBy: $("#refundBy").val().trim(),
                memberMobile: $("#memberMobile").val().trim(),
                memberRealName: $("#memberRealName").val().trim(),*/

                count: $("#count").val().trim() == '' ? 0 : $("#count").val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        exportMemberRefundApply: exportMemberRefundApply,
        showModel: showModel,
        deleteMemberRefundApply: deleteMemberRefundApply
    };
})();

